package problem543;

//543.二叉树的直径
//https://leetcode.cn/problems/diameter-of-binary-tree/?envType=study-plan-v2&envId=top-100-liked

class Solution {
    int ret = 0;
    public int diameterOfBinaryTree(TreeNode root) {
        maxh(root);
        return ret;
    }
    public int maxh(TreeNode root) {
        if(root == null) return 0;
        int l = maxh(root.left);
        int r = maxh(root.right);
        ret = Math.max(l+r, ret);
        return Math.max(l, r) + 1;
    }
}